{% extends "base.html" %}
{% block content %}
{% from 'include/input_macros.html' import input, checkbox, select, copy_to_clipboard %}
<script src="/inc/users.js"></script>
{% include 'include/del_confirm.html' %}
<input type="hidden" id="new-group" name="new-group" value="{{ group }}">
<input type="hidden" id="new-server-group-add" name="new-server-group-add" value="{{ group }}" >
<input type="hidden" id="new-sshgroup" name="new-sshgroup" value="{{ group }}" >
{{ input('new-telegram-group-add', type='hidden', value=group) }}
{{ input('new-slack-group-add', type='hidden', value=group) }}
<div id="tabs">
	<ul>
		<li><a href="#users" title="Servers: Manage users - Roxy-WI">Users</a></li>
		<li><a href="#servers" title="Servers: Manage servers - Roxy-WI">Servers</a></li>
		<li><a href="#ssh" title="Servers: Manage SSH credentials - Roxy-WI">SSH credentials</a></li>
		<li><a href="#checker" title="Servers: Manage checker - Roxy-WI">Checker</a></li>
		<li><a href="#settings" title="Admin area: Manage Roxy-WI settings - Roxy-WI">Settings</a></li>
		<li><a href="#installproxy" title="Servers: Proxy service installation - Roxy-WI">Proxy installation</a></li>
		<li><a href="#installmon" title="Servers: Monitoring service installation - Roxy-WI">Monitoring installation</a></li>
		<li><a href="#geolite2" title="Servers: GeoLite2 - Roxy-WI">GeoLite2</a></li>
		<li><a href="#backup" title="Servers: Backup configs - Roxy-WI">Backup</a></li>
		{% include 'include/login.html' %}
	</ul>
	<ul id='browse_histroy'></ul>
	<div id="users">
		{% include 'include/admin_users.html' %}
	</div>

	<div id="servers">
		{% include 'include/admin_servers.html' %}
	</div>

	<div id="ssh">
		{% include 'include/admin_ssh.html' %}
	</div>
	
	<div id="checker"></div>

	<div id="settings">
		{% include 'include/admin_settings.html' %}
	</div>

	<div id="installproxy">
		<table class="overview">
			<caption><h3>Install HAProxy</h3></caption>
			<tr class="overviewHead">
				<td class="padding10 first-collumn">Current version</td>
				<td class="padding10 first-collumn" style="width: 30%;">Available Versions</td>			
				<td class="padding10 first-collumn" style="width: 20%;">Server</td>
				<td>Install as a Docker container</td>
				<td>SYN-flood protection</td>
				<td></td>
			</tr>
			<tr>
				<td id="cur_hap_ver" class="padding10 first-collumn">
				</td>
				<td class="padding10 first-collumn" style="width: 20%;">
					{% set values = dict() %}
					{% set values = {'2.0.5-1':'2.0.5-1','2.0.6-1':'2.0.6-1', '2.0.7-1':'2.0.7-1', '2.0.9-1':'2.0.9-1',
					'2.0.11-1':'2.0.11-1', '2.0.12-1':'2.0.12-1', '2.0.13-1':'2.0.13-1', '2.0.14-1':'2.0.14-1',
					'2.0.17-1':'2.0.17-1','2.0.18-1':'2.0.18-1','2.2.4-1':'2.2.4-1','2.3.0-1':'2.3.0-1','2.3.10-1':'2.3.10-1',
					'2.4.0-1':'2.4.0-1'} %}
					{{ select('hapver',  values=values, selected='2.4.0-1', required='required') }}
				</td>
				<td class="padding10 first-collumn">
					<select autofocus required name="haproxyaddserv" id="haproxyaddserv">
						<option disabled selected>------</option>
						{% for select in servers %}
								<option value="{{ select.2 }}">{{ select.1 }}</option>
						{% endfor %}
					</select>
				</td>
				<td class="syn-flood-protection-field">
					{{ checkbox('haproxy_docker', title="Install as a Docker container") }}
				</td>
				<td class="syn-flood-protection-field">
					{{ checkbox('syn_flood', title="Enable SYN-flood protection", checked='checked') }}
				</td>
				<td>
					<span class="ui-button ui-widget ui-corner-all" id="install" title="Install HAProxy">Install</span>
				</td>
			</tr>
		</table>
		<table>
			<caption><h3>Install Nginx</h3></caption>
			<tr class="overviewHead">
				<td class="padding10 first-collumn">Current version</td>
				<td class="padding10 first-collumn" style="width: 30%;">Available Versions</td>			
				<td class="padding10 first-collumn" style="width: 20%;">Server</td>
				<td>Install as a Docker container</td>
				<td>SYN-flood protection</td>
				<td></td>
			</tr>
			<tr>
				<td id="cur_nginx_ver" class="padding10 first-collumn">
				</td>
				<td class="padding10 first-collumn" style="width: 20%;">
					Roxy-WI will try to install the latest Nginx version from official Nginx repository
				</td>
				<td class="padding10 first-collumn">
					<select autofocus required name="nginxaddserv" id="nginxaddserv">
						<option disabled selected>------</option>
						{% for select in servers %}
								<option value="{{ select.2 }}">{{ select.1 }}</option>
						{% endfor %}
					</select>
				</td>
				<td class="syn-flood-protection-field">
					{{ checkbox('nginx_docker', title="Install as a Docker container") }}
				</td>
				<td class="syn-flood-protection-field">
					{{ checkbox('nginx_syn_flood', title="Enable SYN-flood protection", checked='checked') }}
				</td>
				<td>
					<span class="ui-button ui-widget ui-corner-all" id="nginx_install" title="Install Nginx">Install</span>
				</td>
			</tr>
		</table>
		<div id="ajax"></div>
	</div>

	<div id="installmon">
		{% include 'include/mon_installation.html' %}
	</div>

	<div id="geolite2">
		<table>
			<caption><h3>Install GeoLite2</h3></caption>
			<tr class="overviewHead">
				<td class="padding10 first-collumn">Server</td>
				<td class="padding10 first-collumn" style="width: 30%;">Current installation</td>
				<td class="" style="width: 30%;" title="GeoLite2 DB is released every Tuesday. Should Roxy-WI update it?">Updating</td>
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td class="padding10 first-collumn">
					<select autofocus required name="geoipserv" id="geoipserv">
						<option disabled selected>------</option>
						{% for select in servers %}
						<option value="{{ select.2 }}">{{ select.1 }}</option>
						{% endfor %}
					</select>
				</td>
				<td id="cur_geoip" class="padding10"></td>
				<td class="checkbox">
					{{ checkbox('updating_geoip', title="Update the database?", checked='checked') }}
				</td>
				<td>
					<span class="ui-button ui-widget ui-corner-all" id="geoip_install" title="Install GeoLite2" style="display: none;">Install</span>
				</td>
			</tr>
		</table>
		<div id="ajax-geoip"></div>
		<div class="add-note alert addName alert-info" style="width: inherit; margin-right: 15px; margin-bottom: 15px;">
			Read the "how to" in this <a href="https://roxy-wi.org/howto.py?howto=geoip" title="GeoLite2 description" target="_blank">article</a>
		</div>
		<table style="min-width: 40%;">
			<tr class="overviewHead">
				<th colspan=13 style="background-color: #d1ecf1; padding: 10px;">
					<span id="table_metrics_head" style="position: absolute;margin-left: 43%;">Country codes</span>
					<span id="show_country_codes" class="plus switcher_table_metric" title="Show country codes"></span>
					<span id="hide_country_codes" class="minus switcher_table_metric" title="Hide country codes" style="display: none;"></span>
				</th>
			</tr>
		</table>
		<div id="geoip_country_codes" style="display: none;">
			{% for code in geoip_country_codes %}
			<div class="geoip_country_code" id="{{code.code}}">{{code.code}} ({{code.name}})</div>
			{% endfor %}
		</div>
	</div>

	<div id="backup">
		{% include 'include/admin_backup.html' %}
	</div>
</div>
{% include 'include/admins_dialogs.html' %}
{% include 'include/change_pass_form.html' %}
<script>
	$( function() {
		{% for user in users %}
			$("#role-{{user.0}}" ).selectmenu({
				  width: 100
			});	
		{% endfor %}
		{% for server in servers %}
			$("#slavefor-{{server.0}}" ).selectmenu({
			  width: 130
			});
			$("#credentials-{{server.0}}" ).selectmenu({
			  width: 150
			});
		{% endfor %}
		{% for ssh in sshs %}
			$("#sshgroup-{{ ssh.0}}" ).selectmenu({
				  width: 150
			});
		{% endfor %}
		{% for server in backups %}
			$("#backup-time-{{ server.id}}" ).selectmenu({
				width: 100
			});
			$("#backup-type-{{server.id}}" ).selectmenu({
				width: 130
			});
			$("#backup-credentials-{{server.id}}" ).selectmenu({
				width: 150
			});
		{% endfor %}
	});
</script>
<link href="/inc/servers.css" rel="stylesheet"/>
{% endblock %}
